<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}

if($_POST['sub']!=''){

	srand(seed());
    $encrypt=mt_rand (100000,999999);
    
    $id=empty($_POST['id'])?0:(int)$_POST['id'];
	unset($_POST['id']);
	unset($_POST['sub']);
	$data=array('username'=>trim($_POST['username']),
    "password"=>md5(trim($_POST["password"]).EZKEY.$encrypt),
    "nickname"=>trim($_POST["nickname"]),
    "email"=>trim($_POST["email"]),
    "groupid"=>trim($_POST["groupid"]),
    "regip"=>get_client_ip(),
    "regdate"=>time(),
    "lastdate"=>time(),
    "lastip"=>get_client_ip(),
    "encrypt"=>$encrypt,
    "mobile"=>trim($_POST["mobile"])   
    );

    if($id==0){
        if(trim($_POST['username'])==""){
            jumpajax('300','用户名不能为空','');
        }        
        if(trim($_POST['password'])==""){
            jumpajax('300','登录密码不能为空','');
        }
        if(trim($_POST['password'])!=trim($_POST['password1'])){
            jumpajax('300','两次输入密码不同！','');
        }
    
    }else{
        unset($data["username"]); 
        if(trim($_POST['password'])==""){
            
            unset($data["password"]);    
            unset($data["encrypt"]); 
        }
        
    }
    if(trim($_POST['email'])==""){
        jumpajax('300','邮件地址不能为空','');
    }   
    if(empty($id)){
    if ($ezhand->check_user($data["username"]) == 'false') {
        jumpajax('300','用户名“'.$data["username"].'”已经被使用','');
        exit;  
    }
    
    }
    if ($ezhand->check_nickname($data["nickname"],$id) == 'false') {
        jumpajax('300','昵称“'.$data["nickname"].'”已经被使用','');
        exit;  
    }
    if ($ezhand->check_email($data["email"],$id) == 'false') {
        jumpajax('300','邮件地址“'.$data["email"].'”已经被使用','');
        exit;  
    }        
 	if($id==0){
 	    
	    $id=$ezhand->insert("member",$data);
		jumpajax('200','保存成功','','closeCurrent');
	}
	else{
	    $ezhand->update("member",$data,'id="'.$id.'"');
		jumpajax('200','修改成功','','closeCurrent');
	}
}
else{
	$id=empty($_GET['id'])?0:(int)$_GET['id'];
    $usergroup=ez_get_cache("usergroup");
    if($id==0){
	    $row=array();
	}
	else{
	    $row=$ezhand->select("member",'*','id="'.$id.'"');
        if(empty($row)){
          jumpajax('200','用户信息不存在!','','closeCurrent');  
        }
	}
}
?>